package day19.zhiyou100;


// 测试类
class DeadLockThread {
    public static void main(String[] args) {
        DeadLock d1 = new DeadLock();

        //创建两个线程对象
        Thread t1 = new Thread(d1);
        Thread t2 = new Thread(d1);

        t1.start();
        t2.start();
    }
}

// 当前它是一个线程类
public class DeadLock implements Runnable{

    private Object o1 = new Object();
    private Object o2 = new Object();

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i % 2 == 0) { // 偶数
                synchronized (o1) {// 1
                    System.out.println("对o1对象上锁----->");
                    synchronized (o2) {// 1
                        System.out.println("偶数值为：" +i);
                    }
                }
            } else {
                synchronized (o2) {
                    System.out.println("对o2对象上锁------>");
                    synchronized (o1) {
                        System.out.println("奇数值为：" + i);
                    }
                }
            }

        }
    }

}
